<template>
	<view class="container">
		<view class="yy-mz-head">
			<view 
			class="yy-mz-headItem"
			@click="changedata(index,item.dateAll.yearDate,item.disabled)"
			v-for="(item,index) in datalist"
			:key="index"
			:class="[currnum == index?'yy-mz-headShow':'',item.disabled === false ? 'yy-mz-headShowop':'']">		
				<!-- <text v-if="item.mon == ''&&item.day == ''">{{item.dec}}</text> -->
				<text>{{item.dateAll.date}}</text>
				<text>{{item.dateAll.week}}</text>
			</view>
		</view>
		<view class="yy-mz-con">
			<view class="yy-mz-conItem" v-for="(item,index) in docList" :key="index" @click="docdetail(item.id,item.is_full)">
				<view class="yy-mz-conItem-l-no">
					<image :src="item.avatar" mode="widthFix"></image>
				</view>
				<view class="yy-mz-conItem-r">
					<view class="yy-mz-conItem-r-intro">
						<view class="yy-mz-conItem-name">
							<text>{{item.nickname}}</text>
							<text>{{item.title}}</text>
						</view>
						<view v-if="item.is_full == 0" class="yy-mz-conItem-curr">预约挂号</view>
						<view v-else class="" class="yy-mz-conItem-curr curred">已约满</view>
					</view>
					<view class="yy-mz-conItem-r-des">{{item.bio}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import app from '../../App.vue'
	export default{
		data(){
			return{
				currnum:0,
				// dataList:[],
				mzId:'',			//门诊id
				name:'',			//门诊时间
				data:'',			//门诊时间
				docList:[],
				datalist:[]
			}
		},
		
		onLoad(options) {
			this.mzId = options.id
			this.name = options.name
			this.gettimelist()
		},
		onShow() {
			// c7685d7b-8083-4de0-be61-0cd42fbdc1bc
			// this.getdata()
		},
		onReady() {
			uni.setNavigationBarTitle({
				title:`${this.name}门诊`
			})
		},
		methods:{
			changedata(e,data,status){
				this.currnum = e
				this.data = data
				if(status === false){
					uni.showToast({
						title: '该天无法预约',
						icon: 'none',
						mask: true
					})
					this.docList = []
				}else{
					let date = data
					this.getdata(date)
				}
			},
			
			
			
			gettimelist(){
				let that = this
				let data = {
					department_id:that.mzId,
				}
				app.post('api/user_scheduling/getDateList',data).then(res=>{
					if(res.code == 1){
						that.datalist = res.data
						// console(typeof res.data)
						var weeks = ['日', '一', '二', '三', '四', '五', '六'];
						let timelist = []
						for(var i=0;i< that.datalist.length ;i++){
							let arrdata = {}
							that.datalist[i].dateAll = {}
							let date1 = that.datalist[i].date
							// console.log(date1)
							let date = new Date(date1*1000)
							
							let year = date.getFullYear()
							
							let month = date.getMonth() + 1
							month = month<10 ? "0"+month:month
							
							let day = date.getDate()
							day = day < 10 ? '0' + day:day
							
							
							var week = weeks[date.getDay()>6?0:date.getDay()];
							
							arrdata.date = month + '.' + day
							arrdata.week = '周 ' + week
							arrdata.yearDate = year + '-' + month + '-' + day
							// arrdata.disabled = list[i].disabled
							that.datalist[i].dateAll = arrdata
						}
						this.getdata()
					}else if(res.code == 0){
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						})
					}else if(res.code == 401){
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						})
					}
				}).catch(err=>{
					uni.showToast({
						title: err.msg,
						icon: 'none',
						mask: true
					})
				})
			},
			
			
			
			
			getdata(date){							//指定时间的医生列表
				let that = this,
				data = {
					department_id:that.mzId,
					date:that.currnum == 0?that.datalist[0].dateAll.yearDate:date
				}
				app.post('api/user_scheduling/getDoctorList',data).then(res=>{
					if(res.code == 1){
						if(res.data != ''){
							that.docList = res.data
						}else{
							that.docList = []
							uni.showToast({
								title: '暂无数据',
								icon: 'none',
								mask: true
							})
						}
					}else if(res.code == 0){
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						})
					}else if(res.code == 401){
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						})
					}
				}).catch(err=>{
					uni.showToast({
						title: err.msg,
						icon: 'none',
						mask: true
					})
				})
			},
			docdetail(id,status){
				let that = this
				uni.showLoading({
					title:'加载中',
					success() {
						setTimeout(function(){
							uni.hideLoading()
							uni.navigateTo({
								url:'/pages/yuyue/doc?id='+id+'&status='+status+'&mzId='+that.mzId
							})
						},1300)
					}
				})
			},
			yypages(id){
				uni.showLoading({
					title:'加载中',
					success() {
						setTimeout(function(){
							uni.hideLoading()
							uni.navigateTo({
								url:'/pages/yuyue/choosedate?id='+id
							})
						},1300)
					}
				})
			}
		}
	}
</script>

<style>
	@import url("../../common/yuyuemenzhen.css");
</style>
